package xc.common.viewlib.procustom

import android.app.Activity
import android.graphics.Color
import android.graphics.Typeface
import android.view.View
import xc.common.viewlib.BasicViewConstants
import xc.common.viewlib.R
import xc.common.viewlib.view.customview.TitleLayout

fun TitleLayout.removeTopPadding() {
    findViewById<View>(R.id.ll_title_wraper).setPadding(0, 0, 0, 0)
}

fun TitleLayout.extInitCommonBgAutoBack(activity: Activity, title: String) {
    initTitle(activity, title, "#000000", true)
}

fun TitleLayout.extInitWhiteBgAutoBack(activity: Activity, title: String) {
    initTitle(activity, title, "#00FFFFFF", true)
    titleTextView.typeface = (Typeface.defaultFromStyle(Typeface.BOLD))
    titleTextView.setTextColor(Color.parseColor("#FFFFFF"))

    setRightTextColor(
        BasicViewConstants.context.resources.getColor(
            R.color.bv_main_text_color_light
        )
    )
    setBackIcon(R.mipmap.bv_white_back_icon)
    setOnBackClickListener {
        activity.finish()
    }
}

fun TitleLayout.extSetRightBtnInfo(resouceId: Int, onClickListener: (v: View) -> Unit) {
    setRightBtnIcon(resouceId)
    setRightBtnClickListener(onClickListener)
}

fun TitleLayout.initCommonRightTextView(msg: String, onClickListener: View.OnClickListener) {
    rightText = msg
    setRightTextColor(Color.parseColor("#0140C3"))
    setRightTextClickListener(onClickListener)
}

fun TitleLayout.initTitle(activity: Activity, title: String, bg: String, isBack: Boolean) {
    this.setTitleText(title)
    this.setBackgroundColor(Color.parseColor(bg))
    if (isBack) {
        this.setOnBackClickListener {
            activity.finish()
        }
    }
}